#include "Vector.h"
#include "Matrix.h"

float _dot(float* l,float* r,int num){
	float ret = 0;
	for (int i = 0 ; i < num ; ++i)
	{
		ret += l[i]*r[i];
	}
	return ret;
};

void _cross(float* l,float* r,float* ret){
/*
	First of all,vector-cross comes from its geometry meaning:
		result is another vector which perpendicular to both of them,
		and direction satisfy right-hand rule
		
	math proof (Vec3),import i,j,k which are Perpendicular to each other,so:
	Convert cross to dot !!!!!

	i = j x k; j = k x i; k = i x j;

	(Ux*i+Uy*j+Uz*k)*(Vx*i+Vy*j+Vz*k)  
	=	Ux*Vx*i*i+Ux*Vy*(ij)+Ux*Vz(ik) + 
		Uy*Vx*(ji)+Uy*Vy*j*j+Uy*Vz(jk) + 
		Uz*Vx*(ki)+Uz*Vy*(kj)+Uz*Vz*k*k   
	=	0         +Ux*Vy*(k) +Ux*Vz(-j) + 
		Uy*Vx*(-k)+0         +Uy*Vz(i) + 
		Uz*Vx*(j) +Uz*Vy*(-i) +0          
	=	(  Uy*Vz - Uz*Vy)*i +
		(- Ux*Vz + Uz*Vx)*j +
		(  Ux*Vy - Uy*Vx)*k 

	so,format is (Ux*Vx - ...)*i + (Uy*Vy - ...)*j + ... 
*/
	ret[0] =  l[1]*r[2] - l[2]*r[1];
	ret[1] = -l[0]*r[2] + l[2]*r[0];
	ret[2] =  l[0]*r[1] - l[1]*r[0]; 
};

Vec2::Vec2(float x,float y)
{
	this->x = x;this->y = y;
}


Vec2::~Vec2(void)
{
}

Vec3::Vec3(float x,float y,float z)
{
	this->x = x;this->y = y;
	this->z = z;
}
Vec3::Vec3(Vec2& vec2,float z)
{
	this->x = vec2.x;this->y = vec2.y;
	this->z = z;
}
Vec3::~Vec3()
{
}

Vec4::Vec4(float x,float y,float z,float w)
{
	this->x = x;this->y = y;this->z = z;
	this->w = w;
}

Vec4::~Vec4()
{
}

Vec4 Vec4::operator*( Mat4* m )
{
	Vec4 ret;
	Mat4 M = *m;
	for (int i = 0; i < 4; ++i)
	{
		ret[i] = x*M[0][i] + y*M[1][i] + z*M[2][i] + w*M[3][i]; 
	}
	return ret;
}
